<template>
  <div>
    <van-nav-bar title="商品详情" left-arrow @click-left="$router.back()">
      <template #right>
        <van-icon name="ellipsis" />
      </template>
    </van-nav-bar>
    <!-- 商品详情 -->
    <div class="product-info">
      <img style="width: 100%" :src="info.goodsCoverImg" alt="" />
      <div class="info-goodsName">
        {{ info.goodsName }}
      </div>
      <p class="info-p">免邮费 顺丰快递</p>
      <!-- <p>{{ info.goodsIntro }}</p> -->
      <p class="info-price">￥{{ info.sellingPrice }}</p>
      <ul class="info-ul">
        <li>概述</li>
        <li>参数</li>
        <li>安装服务</li>
        <li class="info-ul-li">常见问题</li>
      </ul>
      <div v-html="info.goodsDetailContent" class="info-content"></div>
    </div>
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" />
      <van-goods-action-icon
        icon="cart-o"
        text="购物车"
        :badge="$store.getters.CartNum"
        to="/cart"
      />
      <van-goods-action-button
        @click="clickAddBtn"
        type="warning"
        text="加入购物车"
      />
      <van-goods-action-button type="danger" text="立即购买" />
    </van-goods-action>
  </div>
</template>

<script>
import Vue from "vue";
import { GoodsAction, GoodsActionIcon, GoodsActionButton } from "vant";
Vue.use(GoodsAction);
Vue.use(GoodsActionButton);
Vue.use(GoodsActionIcon);
import { getInfoData } from "@/http/index.js";
export default {
  name: "Info",
  data() {
    return {
      info: {},
    };
  },
  created() {
    this.getData();
    this.$store.dispatch("getCartData");
  },
  mounted() {},
  methods: {
    getData() {
      getInfoData(this.$route.params.productId).then((res) => {
        //console.log("res:", res);
        this.info = res.data;
      });
    },
    clickAddBtn() {
      let obj = {
        id:this.$route.params.productId,
        count:1
      }
      this.$store.dispatch("addCartData",obj);
    },
  },
};
</script>

<style lang="less" scoped>
.van-nav-bar {
  position: fixed;
  width: 100%;
  height: 40px;
  top: 0;
  left: 0;
  z-index: 100;
  line-height: 40px;
  padding: 0 0.26667rem;
  box-sizing: border-box;
  background: #fff;
  border-bottom: 0.02667rem solid #dcdcdc;
}

.product-info {
  margin-top: 1.17333rem;
  padding: 0 0.26667rem;

  .info-goodsName {
    font-size: 17px;
    text-align: left;
    color: #333;
  }

  .info-p {
    font-size: 13px;
    text-align: left;
    color: #999;
  }

  .info-price {
    color: #f63515;
    font-size: 21px;
    text-align: left;
  }

  .info-ul {
    width: 100%;
    height: 30px;
    margin: 26px 0;
    display: flex;
    justify-content: space-between;

    li {
      flex: 1;
      padding: 0.13333rem 0;
      text-align: center;
      font-size: 0.4rem;
      border-right: 0.02667rem solid #999;
      box-sizing: border-box;
    }
  }

  .info-ul .info-ul-li {
    border-right: none;
  }

  .info-content {
    padding: 0 0.53333rem;
  }
}

.van-goods-action {
  .van-info {
    position: absolute;
    top: -17px;
    right: 13px;
  }
}
</style>
